﻿Imports System.Windows.Input

''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
Partial Public Class VMParametrageElement
    Inherits VMBase

    Dim _value As Object
    Dim _UndoCommand As ICommand = New SCommand(AddressOf Undo)
    Dim _RedoCommand As ICommand = New SCommand(AddressOf Redo)
    Dim _UndoStack As New Stack(Of Object)
    Dim _RedoStack As New Stack(Of Object)

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <remarks></remarks>
    Sub New(ByVal name As String)
        Me.Name = name
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <param name="type"></param>
    ''' <remarks></remarks>
    Sub New(ByVal name As String, ByVal type As String)
        Me.Name = name
        Me.Type = type
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <remarks></remarks>
    Sub New(ByVal owner As VMParametrage, ByVal name As String)
        Me.Name = name
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <param name="type"></param>
    ''' <remarks></remarks>
    Sub New(ByVal owner As VMParametrage, ByVal name As String, ByVal type As String)
        Me.Name = name
        Me.Type = type
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <param name="type"></param>
    ''' <param name="editoroptions"></param>
    ''' <remarks></remarks>
    Sub New(ByVal name As String, ByVal type As String, ByVal editoroptions As Object)
        Me.Name = name
        Me.Type = type
        Me.EditorOptions = editoroptions
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="name"></param>
    ''' <param name="type"></param>
    ''' <param name="editoroptions"></param>
    ''' <remarks></remarks>
    Sub New(ByVal owner As VMParametrage, ByVal name As String, ByVal type As String, ByVal editoroptions As Object)
        Me.Name = name
        Me.Type = type
        Me.EditorOptions = editoroptions
    End Sub


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Groupe As String

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Type As String

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Name As String

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Editor As String

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property EditorOptions As Object

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Presentor As String

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Value As Object
        Get
            Return _value
        End Get
        Set(ByVal value As Object)
            _value = value
            _UndoStack.Push(value)
            _RedoStack.Clear()
            OnPropertyChanged("Value")
        End Set
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property UndoCommand As ICommand
        Get
            Return _UndoCommand
        End Get
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property RedoCommand As ICommand
        Get
            Return _RedoCommand
        End Get
    End Property

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="param"></param>
    ''' <remarks></remarks>
    Sub Undo(ByVal param As Object)
        If _UndoStack.Count > 0 Then
            '
            'If _RedoStack.Count = 0 Then
            '    If _UndoStack.Count > 1 Then
            '        _RedoStack.Push(_UndoStack.Pop())
            '        _value = _UndoStack.Pop()
            '    End If
            'Else
            '    _value = _UndoStack.Pop()
            '    _RedoStack.Push(_value)

            'End If

            _value = _UndoStack.Pop()
            _RedoStack.Push(_value)
            OnPropertyChanged("Value")
        End If
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="param"></param>
    ''' <remarks></remarks>
    Sub Redo(ByVal param As Object)
        If _RedoStack.Count > 0 Then
            _value = _RedoStack.Pop()
            _UndoStack.Push(_value)
            OnPropertyChanged("Value")
        End If
    End Sub


End Class